home *** CD-ROM | disk | FTP | other *** search
/ Delphi 2 - Developers' Solutions / Delphi 2 Developers' Solutions.iso / dds / chap09 / howto02 / delphi10 / cciccinf.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-06-12  |  3.3 KB  |  108 lines

  1. unit Cciccinf;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, StdCtrls, Buttons, ExtCtrls, Grids, Outline, CCWSock;
  8.  
  9. type
  10.   TCCICInfoDlg = class(TForm)
  11.     Panel1: TPanel;
  12.     BitBtn1: TBitBtn;
  13.     BitBtn2: TBitBtn;
  14.     Panel4: TPanel;
  15.     ListBox2: TListBox;
  16.     Panel2: TPanel;
  17.     Edit1: TEdit;
  18.     Panel3: TPanel;
  19.     Edit2: TEdit;
  20.     Panel5: TPanel;
  21.     Edit3: TEdit;
  22.     Panel8: TPanel;
  23.     Edit4: TEdit;
  24.     Panel9: TPanel;
  25.     Edit5: TEdit;
  26.     Panel6: TPanel;
  27.     Outline1: TOutline;
  28.     Label1: TLabel;
  29.     Label2: TLabel;
  30.     Button1: TButton;
  31.     Button2: TButton;
  32.     Button3: TButton;
  33.     Button4: TButton;
  34.     procedure Button1Click(Sender: TObject);
  35.   private
  36.     { Private declarations }
  37.   public
  38.     { Public declarations }
  39.   end;
  40.  
  41. var
  42.   CCICInfoDlg: TCCICInfoDlg;
  43.  
  44. implementation
  45.  
  46. uses CCICCFrm;
  47.  
  48. function inet_addr( IPAddressName : PChar ) :
  49.           Unsigned_Long_Integer; far; external 'WINSOCK';
  50. function gethostbyname( TheName : PChar ) :
  51.           PHost_Entry; far; external 'WINSOCK';
  52.  
  53. {$R *.DFM}
  54. procedure TCCICInfoDlg.Button1Click(Sender: TObject);
  55. var TempSocket : TCCSocket; { Used for IP Address info }
  56.     DataBuffer : array[ 0 .. 256 ] of char;
  57. begin
  58.   case Tag of
  59.     1 : begin  { Get IP Address Mode }
  60.           { Create the dummy socket }
  61.           TempSocket := TCCSocket.Create( Self );
  62.           TempSocket.Parent := Self;
  63.           { Use it to get the info }
  64.           with TempSocket do
  65.           begin
  66.             { Move the IP address into the data buffer }
  67.             StrPCopy( DataBuffer , Edit1.Text );
  68.             { Turn it into a real IP address in binary form }
  69.             Socket_IP_Address.Socket_Address.Full_Internet_Address :=
  70.              inet_addr( DataBuffer );
  71.             { If not found then do remote lookup }
  72.             if Socket_IP_Address.Socket_Address.Full_Internet_Address = INADDR_NONE then
  73.             begin
  74.               { Call blocking function on IP name }
  75.               Socket_Host_Entry := gethostbyname( DataBuffer );
  76.               { If still no good then error out and exit }
  77.               if Socket_Host_Entry = nil then
  78.               begin
  79.                 Edit2.Text := 'Could Not Convert Host Name';
  80.                 Edit3.Text := '';
  81.               end
  82.               else
  83.               begin
  84.                 { Otherwise get the address }
  85.                 Socket_IP_Address.Socket_Address :=
  86.                  Socket_Host_Entry^.Host_Address^^;
  87.                 Edit2.Text :=
  88.                  IntToStr( Socket_IP_Address.Socket_Address.Net_Byte ) + '.' +
  89.                  IntToStr( Socket_IP_Address.Socket_Address.Host_Byte ) + '.' +
  90.                  IntToStr( Socket_IP_Address.Socket_Address.Local_Host_Byte ) +
  91.                  '.' + IntToStr(
  92.                  Socket_IP_Address.Socket_Address.Local_Machine_Byte );
  93.                 Edit3.Text :=
  94.                  IntToStr( Socket_IP_Address.Socket_Address.
  95.                             Full_Internet_Address );
  96.               end;
  97.             end;
  98.           end;
  99.           { Free the dummy socket }
  100.           TempSocket.Free;
  101.         end;
  102.   end;
  103. end;
  104.  
  105. { This procedure saves the newly modified list of stuff to its base }
  106. { This method cancels any changes made from entries in current setup & exits}
  107. end.
  108.